package May;

import java.util.Scanner;

public class Test10ArrayUsing04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[10];

        System.out.println("请输入10个数字，我将把它们塞入到一个数组当中");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
        format(arr, "该数组的内容是[");

        System.out.println("请你输入想要得到的数组范围（索引为0-9）");
        int[] copyArr=compare(arr);
        format(copyArr,"你选择的索引范围是：");


    }

    public static void format(int[] arr_f, String usage) {
        System.out.print(usage);
        for (int i = 0; i < arr_f.length; i++) {
            if (i < arr_f.length - 1) {
                System.out.print(arr_f[i] + ",");
            } else {
                System.out.print(arr_f[i] + "]");
            }
        }
    }

    public static int[] compare(int[] arr_c) {
        Scanner scanner = new Scanner(System.in);
        int start = scanner.nextInt();
        int end = scanner.nextInt();
        int[] newArr = new int[end - start+1];
        int result = 0;
        for (int i = start; i <= end; i++) {
            newArr[result] = arr_c[i];
            result++;
        }
        return newArr;
    }
}
